﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Peer.Game
{
    public class OperationRequest
    {
        private readonly Dictionary<byte, byte[]> Parameters;

        public OperationRequest(byte[] bytes)
        {
            Parameters = new Dictionary<byte, byte[]>();
            var result = MTP.Serialize.MTPSerialize.DeserializeSplit(bytes);
            this.OperationCode = MTP.Serialize.MTPSerialize.Deserialize<byte>(result[0]);
           
            for (int i = 1; i < result.Count; i += 2)
            {
                var key = MTP.Serialize.MTPSerialize.Deserialize<byte>(result[i]);
                Parameters.Add(key, result[i + 1]);
            }
        }

        public T GetValue<T>(byte key)
        {
            if (!Parameters.ContainsKey(key))
            {
                return default;
            }
            return MTP.Serialize.MTPSerialize.Deserialize<T>(Parameters[key]);
        }


        public byte OperationCode { get; private set; }
    }
}
